{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 1.  2.  3.  4.  5.  6.  7.  8.  9. 10. 11. 12. 13. 14. 15.]\n"
     ]
    },
    {
     "ename": "AttributeError",
     "evalue": "module 'tensorflow' has no attribute 'placeholder'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-1-4d376305813b>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m     30\u001b[0m     \u001b[0mdateNormal\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mi\u001b[0m\u001b[1;33m/\u001b[0m\u001b[1;36m14.0\u001b[0m\u001b[1;33m;\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     31\u001b[0m     \u001b[0mpriceNormal\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mendPrice\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m/\u001b[0m\u001b[1;36m3000.0\u001b[0m\u001b[1;33m;\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 32\u001b[1;33m \u001b[0mx\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mplaceholder\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfloat32\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     33\u001b[0m \u001b[0my\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mplaceholder\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfloat32\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     34\u001b[0m \u001b[1;31m# B\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mAttributeError\u001b[0m: module 'tensorflow' has no attribute 'placeholder'"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD4CAYAAAAAczaOAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAARfElEQVR4nO3dfYxldX3H8fdHFikKVBsGi7NLF81iBasg42YrsU18KFs1LG3Tdk0LNDbdhqwWDH0QbLT+YWOsYiWtGCq4km6kVNZCG6iiJTVNeOjsdnVZRsqmoIxsZU1T2bQpCH77xz2r19nZO3dkdu7M/N6v5GbP/Z5z7v2e2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D1fVgar6LrADeO2IexrGt5KcCtD9+/iI+5lTkkuAtwK/UUv3QqWX0hsAfKX7eVsN7Eryk8/2hVdi6P8rsC7J6UmeS+9g2G0j7umIkoTePuepqrp61P0MUlVXVtXqqlpL7+v6T1W1ZEejVfWfwKNJXtaV3gA8MMKWBvkGsCHJ87rviTewRA86z3AbcEk3fQlw6wh7mVOSjcAfARdU1f+Oup8jqao9VXVKVa3tft6mgVd339PPyooL/e4gzTuAz9P7obm5qvaOtquBzgMuojdq3t093jzqplaQdwLbk3wVOBv409G2M7vu08hngV3AHno/m0vqlgFJPgPcDbwsyXSS3wY+CLwpyUP0zjL54Ch77HeEfv8COBG4s/tZ+8RIm+wcodej815L99ONJGmhrbiRviTpyAx9SWqIoS9JDTH0Jakhhr4kNcTQl6SGGPqS1JD/B7OG5RsAlHPcAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# layer1：激励函数+乘加运算\n",
    "import tensorflow as tf\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "date = np.linspace(1,15,15)\n",
    "endPrice = np.array([2511.90,2538.26,2510.68,2591.66,2732.98,2701.69,2701.29,2678.67,2726.50,2681.50,2739.17,2715.07,2823.58,2864.90,2919.08]\n",
    ")\n",
    "beginPrice = np.array([2438.71,2500.88,2534.95,2512.52,2594.04,2743.26,2697.47,2695.24,2678.23,2722.13,2674.93,2744.13,2717.46,2832.73,2877.40])\n",
    "print(date)\n",
    "plt.figure()\n",
    "for i in range(0,15):\n",
    "    # 1 柱状图\n",
    "    dateOne = np.zeros([2])\n",
    "    dateOne[0] = i;\n",
    "    dateOne[1] = i;\n",
    "    priceOne = np.zeros([2])\n",
    "    priceOne[0] = beginPrice[i]\n",
    "    priceOne[1] = endPrice[i]\n",
    "    if endPrice[i]>beginPrice[i]:\n",
    "        plt.plot(dateOne,priceOne,'r',lw=8)\n",
    "    else:\n",
    "        plt.plot(dateOne,priceOne,'g',lw=8)\n",
    "#plt.show()\n",
    "# A(15x1)*w1(1x10)+b1(1*10) = B(15x10)\n",
    "# B(15x10)*w2(10x1)+b2(15x1) = C(15x1)\n",
    "# 1 A B C \n",
    "dateNormal = np.zeros([15,1])\n",
    "priceNormal = np.zeros([15,1])\n",
    "for i in range(0,15):\n",
    "    dateNormal[i,0] = i/14.0;\n",
    "    priceNormal[i,0] = endPrice[i]/3000.0;\n",
    "x = tf.compat.v1.placeholder(tf.float32,[None,1])\n",
    "y = tf.compat.v1.placeholder(tf.float32,[None,1])\n",
    "# B\n",
    "w1 = tf.Variable(tf.random_uniform([1,10],0,1))\n",
    "b1 = tf.Variable(tf.zeros([1,10]))\n",
    "wb1 = tf.matmul(x,w1)+b1\n",
    "layer1 = tf.nn.relu(wb1) # 激励函数\n",
    "# C\n",
    "w2 = tf.Variable(tf.random_uniform([10,1],0,1))\n",
    "b2 = tf.Variable(tf.zeros([15,1]))\n",
    "wb2 = tf.matmul(layer1,w2)+b2\n",
    "layer2 = tf.nn.relu(wb2)\n",
    "loss = tf.reduce_mean(tf.square(y-layer2))#y 真实 layer2 计算\n",
    "train_step = tf.train.GradientDescentOptimizer(0.1).minimize(loss)\n",
    "with tf.Session() as sess:\n",
    "    sess.run(tf.global_variables_initializer())\n",
    "    for i in range(0,10000):\n",
    "        sess.run(train_step,feed_dict={x:dateNormal,y:priceNormal})\n",
    "    # w1w2 b1b2  A + wb -->layer2\n",
    "    pred = sess.run(layer2,feed_dict={x:dateNormal})\n",
    "    predPrice = np.zeros([15,1])\n",
    "    for i in range(0,15):\n",
    "        predPrice[i,0]=(pred*3000)[i,0]\n",
    "    plt.plot(date,predPrice,'b',lw=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
